﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TextEditor.TextDocument.Control
{
    public partial class frmSetFont : Form
    {
        public frmSetFont()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
        private string z_fontname = string.Empty;

        public string Z_fontname
        {
            get { return z_fontname; }
            set { z_fontname = value; }
        }
        private string e_fontname = string.Empty;

        public string E_fontname
        {
            get { return e_fontname; }
            set { e_fontname = value; }
        }
        private int fontSize = 7;

        public int FontSize
        {
            get { return fontSize; }
            set { fontSize = value; }
        }

        public string SetF1
        {
            set
            {
                this.textBox1.Text = value;
            }
        }

        public string SetF2
        {
            set
            {
                this.textBox2.Text = value;
            }
        }

        public int SetF3
        {
            set
            {
                this.numericUpDown1.Value = value;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Z_fontname = this.textBox1.Text;
            E_fontname = this.textBox2.Text;
            FontSize = Convert.ToInt32(this.numericUpDown1.Value);
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string fontName = GetFontName();
            if (!string.IsNullOrEmpty(fontName))
                this.textBox1.Text = fontName;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string fontName = GetFontName();
            if (!string.IsNullOrEmpty(fontName))
                this.textBox2.Text = fontName;
        }

        private string GetFontName()
        {
            using (FontDialog f = new FontDialog())
            {
                f.Font = new Font(this.textBox1.Text, Convert.ToInt32(this.numericUpDown1.Value));
                f.ShowColor = false;
                f.ShowEffects = false;
                if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    return f.Font.Name;
                }
            }
            return string.Empty;
        }
    }
}
